import TabMenu from './data';
import TabMenu2 from './data2';
const app = getApp();

Component({
  data: {
    active: 0,
    list: TabMenu,
  },

  methods: {
    onChange(event) {
      this.setData({
        active: event.detail.value
      });
      console.log('--onChange--');
      console.log(this.data.list[event.detail.value].url.startsWith('/') ?
        this.data.list[event.detail.value].url :
        `/${this.data.list[event.detail.value].url}`);

      wx.switchTab({
        url: this.data.list[event.detail.value].url.startsWith('/') ?
          this.data.list[event.detail.value].url : `/${this.data.list[event.detail.value].url}`,
      });
    },

    init() {
      //
      // console.log('--------------11111----------');
      // console.log('用户身份：' + app.globalData.userIdentity);
      // if (
      //   app.globalData.userIdentity === '1' ||
      //   app.globalData.userIdentity === '2' ||
      //   app.globalData.userIdentity === '3'
      // ) {
      //   console.log('--------------true----------');

      //   const list = TabMenu2;
      //   this.setData({ list });
      // }

      const page = getCurrentPages().pop();
      const route = page ? page.route.split('?')[0] : '';

      const active = this.data.list.findIndex(
        (item) => (item.url.startsWith('/') ? item.url.substr(1) : item.url) === `${route}`,
      );
      console.log('--init--');
      console.log(active);
      console.log(`${route}`);
      this.setData({
        active
      });
    },
  },
});